<template>
	<div class="ui-images-cells">
		<a class="cell-item" v-for="(item, index) in value" :key="index">
			<ImageCell :src="item" :width="width"></ImageCell>
			<div v-if="preview" class="preview">
				<Icon type="ios-eye" />
			</div>
			<div v-if="remove" class="remove" @click="handleRemove(index)">
				<Icon type="md-close-circle" />
			</div>
		</a>
	</div>
</template>

<script>
import ImageCell from './index.vue';
export default {
	name: 'ImageCells',
	components: {
		ImageCell
	},
	props: {
		value: {
			type: Array,
			default: function() {
				return [];
			}
		},
		width: {
			type: String | Number,
			default: ''
		},
		preview: {
			type: Boolean,
			default: false
		},
		remove: {
			type: Boolean,
			default: false
		}
	},
	methods: {
		handleRemove(index) {
			let values = this.value;
			values.splice(index, 1);
			this.$emit('input', values);
		}
	}
}
</script>

<style>
.ui-images-cells {
	display: inline-block;
	font-size: 0;
	vertical-align: top;
}
.ui-images-cells .cell-item {
	position: relative;
	display: inline-block;
	margin-right: 10px;
	vertical-align: top;
}
.ui-images-cells .cell-item .preview {
	display: none;
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	font-size: 18px;
	color: #fff;
	text-align: center;
	background-color: rgba(0, 0, 0, .1);
	z-index: 2;
}
.ui-images-cells .cell-item:hover .preview {
	display: flex;
}
.ui-images-cells .cell-item .ui-image-cell {
	overflow: initial;
}
.ui-images-cells .cell-item .remove {
	position: absolute;
	right: -8px;
	top: -8px;
	font-size: 16px;
	line-height: 1;
	z-index: 3;
}
</style>